﻿﻿@model IEnumerable<Role>

@{
    var modelName = "角色";
    ViewBag.PageTitle = modelName;
    ViewBag.Title = ViewBag.PageTitle + "_安全";
}

<div class="main-content">
    <div class="panel panel-default">
        <header class="panel-heading">
            <h3 class="panel-title">
                <span class="@SettingsManager.Role.IconClass"></span> @ViewBag.PageTitle
            </h3>
        </header>
        <div class="panel-body text-right">
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#ModalRoleForm"><i class="fa fa-pencil fa-fw"></i>新建角色</button>
        </div>
        <table id="RoleList" class="table table-striped table-bordered">            
                @Html.Partial("_List",Model)           
        </table>
    </div>
</div>

<div id="edit-container">
    @Html.Action("EditRole")
</div>

<div id="menus-container">
    
</div>

<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>

@section Footer{
@Scripts.Render("~/bundles/jqueryvalWithBootstrap")
    <script>
        function onAjaxComplete() {
            $('#ModalRoleForm').modal();
        }
        
        function onBeginSave() {
            $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin")
        }
        function onCompleteSave() {
            $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save")
        }
        function updateSuccess(data) {

            switch (data.Status){
                case 4:
                    toastr.warning(data.Message, '@modelName');
                    break;
                case 2:
                    toastr.error(data.Message, '@modelName');
                    break;
                default:
                    toastr.success("操作成功", '@modelName');
                    $('#ModalRoleForm').modal('hide');
                    $("#RoleList").html(data);
            }

        }

        function onAjaxCompleteRoleMenus() {
            $('#modalRoleMenuForm').modal();

            $('input[name=menuId]').change(function () {
                if ($(this).is(":checked")) {
                    var checkboxs = $(this).closest("li").find("input[name=menuId]").prop("checked", "checked");
                } else {
                    $(this).closest("li").find("input[name=menuId]").removeAttr("checked");
                }

            });
        }

        function updateSuccessRoleMenus(data) {
            Common.ShowBox(data.Status, data.Message, "@modelName")
            $('#modalRoleMenuForm').modal('hide');
            

        }



        $(function () {


            var modelName = "@modelName";

            //确认框默认语言
            bootbox.setDefaults({
                locale: "zh_CN"
            });


            //删除数据
            $(document).on("click", '.delete-item', function (e) {
                e.preventDefault();
                var url = $(this).attr('href');

                var that = $(this);

                bootbox.setLocale("zh_CN");

                bootbox.confirm("是否确定删除该项？", function (result) {
                    if (result) {
                        $.post(url, $("#anti-form").serialize(), function (data) {

                            if (data.Status === 1) {
                                toastr.success(data.Message, '@modelName');
                                that.closest("tr").remove();
                            } else {
                                toastr.error(data.Message, '@modelName');
                            }

                        });
                    }
                });
            });


        });
    </script>

}